package tech.abing.spider.task.pipeline.amac;

import java.util.List;

import org.apache.log4j.Logger;

import tech.abing.spider.component.Pipeline;
import tech.abing.spider.model.Proccessable;
import tech.abing.spider.task.model.amac.AdminLicenseDetailEntity;
import tech.abing.spider.task.model.amac.AdminLicenseEntity;
import tech.abing.spider.util.SqlUtil;

public class AdminLicensePipeline implements Pipeline{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -1535611330758647168L;
	private static Logger logger = Logger.getLogger(AdminLicensePipeline.class);
	private static SqlUtil sqlUtil = null;

	public AdminLicensePipeline() {
		if(sqlUtil == null){
			sqlUtil = SqlUtil.getInstance();
			logger.info("数据库连接创建成功！");
		}
	}

	@Override
	public void proccessData(List<Proccessable> objectContainer) {
		if(!objectContainer.isEmpty()){
			for (Proccessable proccessable : objectContainer) {
				if(proccessable.getClass().getName().equals(AdminLicenseEntity.class.getName())){
					sqlUtil.insert(sqlUtil.getConn(),(AdminLicenseEntity)proccessable);
				}
				if(proccessable.getClass().getName().equals(AdminLicenseDetailEntity.class.getName())){
					sqlUtil.insert(sqlUtil.getConn(),(AdminLicenseDetailEntity)proccessable);
				}
			}
		}
		
	}

	@Override
	public void destory() {
		if(sqlUtil != null){
			sqlUtil.closeConn();
			sqlUtil = null;
			logger.info("数据库连接关闭成功！");
		}
	}

}
